<?php

namespace app\admin\controller\system;

use support\Request;
use app\admin\service\system\UploadService;
use app\admin\model\UploadFiles;
use think\facade\Db;

class UploadController 
{
    // 获取资源
    public function list(Request $request)
    {
        $param = $request->all();
        $service = new UploadService();
        return $service->getList($param);
    }
    // 获取分类
    public function cate(Request $request){
        $model = Db::name('upload_class');
        $data = $model->select()->toArray();
        return success($data);
    }
    // 上传文件
    public function Upload()
    {
        $token = getHeaderToken();
        $user  = getJWT($token);
        $model = new UploadFiles();
        $result = $model->upload(
            $class_id = 1, 
            $folder_name = 'files',
            $app = 2,
            $user_id = $user['id'] ?? 0,
            $file = 'file', 
            $exts = []
        );
        return json($result);
    }

}
